>>> first, *middle, last = range(10)
>>> other = [last] * 8
>>> sum(zip(middle, other), tuple())[::2]
Who is the creator of Pandas, and author of the book Python for Data Analysis?
>>> import who_am_i as wai
>>> import numpy as np
>>>
>>> t = np.arange(0.0, 2.0, 0.01)
>>> s = 1 + np.sin(2 * np.pi * t)
>>> wai.plot(t, s)
>>> wai.xlabel('Some numbers')
>>> wai.ylabel('Sine')
>>> wai.title('Sine of some numbers')
>>> wai.grid(True)
>>> wai.show()
From which Monty Python movie is this frame?
Since which version of Python this is valid Python code?
>>> earth_radius = 6_371
>>> print(f'The radius of earth is {earth_radius}')
How many meetups, the Barcelona Python Meetup has held until today?
In a ROC curve plot, what is the Y axis?
Sort them from faster to slower:
>>> import time
>>> import random
>>> import array
>>> import numpy as np
>>> import pandas as pd
>>>
>>> rand_list = [random.randint(0, 2 ** 32) for i in range(1_000_000)]
>>> rand_tuple = tuple(rand_list)
>>> rand_array = array.array('L', rand_list)
>>> rand_numpy = np.array(rand_list, dtype=np.int32)
>>> rand_pandas = pd.Series(rand_list)
>>>
>>> %timeit sum(rand_list)
>>> %timeit sum(rand_tuple)
>>> %timeit sum(rand_array)
>>> %timeit rand_numpy.sum()
>>> %timeit rand_pandas.sum()
In which line this code raises an exception, and which is the exception (e.g. ValueError, TypeError...)?
In[1]: foo = {True, False}
In[2]: foo = {a: not a for a in foo}
In[3]: bar = foo[0]
In[4]: foo = {a: foo for a in foo}
In[5]: bar = foo[0][0]
In[6]: foo = {(a, b): foo for a in foo for b in foo}
In[7]: bar = foo[0, 0][0][0]
In[8]: foo = {(a, b): foo for a in foo.keys() for b in foo.keys()}
In[9]: bar = foo[(0, 0), (0, 0)][0, 0][0][0]
In[10]: foo = {(a, b): foo for a in foo.values() for b in foo.values()}
In[11]: bar = foo[[0, 0], [0, 0]][0, 0][0][0]
In[12]: foo = {(a, b): foo for a in foo.items() for b in foo.items()}
In[13]: bar = foo[[0, 0, 0, 0]][0, 0][0][0]
>>> first, *middle, last = range(10)
>>> other = [2] * 8
>>> sum(zip(middle, other), tuple())[::2]
>>> first, *middle, last = range(10)
>>> first
0
>>> middle
[1, 2, 3, 4, 5, 6, 7, 8]
>>> last
9
>>> other = [last] * 8
>>> other
[9, 9, 9, 9, 9, 9, 9, 9]
>>> zip_val = list(zip(middle, other))
>>> zip_val
[(1, 9), (2, 9), (3, 9), (4, 9), (5, 9), (6, 9), (7, 9), (8, 9)]
>>> sum_val = sum(zip_val, tuple())
>>> sum_val
(1, 9, 2, 9, 3, 9, 4, 9, 5, 9, 6, 9, 7, 9, 8, 9)
>>> sum_val[::2]
(1, 2, 3, 4, 5, 6, 7, 8)
>>> sum(zip(middle, other), tuple())[::2]
(1, 2, 3, 4, 5, 6, 7, 8)
Who is the creator of Pandas, and author of the book Python for Data Analysis?
>>> import who_am_i as wai
>>> import numpy as np
>>>
>>> t = np.arange(0.0, 2.0, 0.01)
>>> s = 1 + np.sin(2 * np.pi * t)
>>> wai.plot(t, s)
>>> wai.xlabel('Some numbers')
>>> wai.ylabel('Sine')
>>> wai.title('Sine of some numbers')
>>> wai.grid(True)
>>> wai.show()
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>>
>>> t = np.arange(0.0, 2.0, 0.01)
>>> s = 1 + np.sin(2 * np.pi * t)
>>> plt.plot(t, s)
>>> plt.xlabel('Some numbers')
>>> plt.ylabel('Sine')
>>> plt.title('Sine of some numbers')
>>> plt.grid(True)
>>> plt.show()
From which Monty Python movie is this frame?
Since which version of Python this is valid Python code?
>>> earth_radius = 6_371
>>> print(f'The radius of earth is {earth_radius}')
Returns 'The radius of earth is 6371' in Python 3.6, and SyntaxError in all previous version, because of the underscore in the number literal, and the f-string.
How many meetups, the Barcelona Python Meetup has held until today?
In a ROC curve plot, what is the Y axis?
Sort them from faster to slower:
>>> import time
>>> import random
>>> import array
>>> import numpy as np
>>> import pandas as pd
>>>
>>> rand_list = [random.randint(0, 2 ** 32) for i in range(1_000_000)]
>>> rand_tuple = tuple(rand_list)
>>> rand_array = array.array('L', rand_list)
>>> rand_numpy = np.array(rand_list, dtype=np.int32)
>>> rand_pandas = pd.Series(rand_list)
>>>
>>> %timeit sum(rand_list) # 18.8 ms ± 251 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
>>> %timeit sum(rand_tuple) # 18.4 ms ± 289 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
>>> %timeit sum(rand_array) # 46 ms ± 1.46 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
>>> %timeit rand_numpy.sum() # 1.1 ms ± 13.7 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
>>> %timeit rand_pandas.sum() # 1.37 ms ± 3.8 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
The one in the left
In which line this code raises an exception, and which is the exception (e.g. ValueError, TypeError...)?
In[1]: foo = {True, False}
In[2]: foo = {a: not a for a in foo}
In[3]: bar = foo[0]
In[0]: foo
{False: True, True: False}
In[4]: foo = {a: foo for a in foo}
In[5]: bar = foo[0][0]
In[0]: foo
{False: {False: True, True: False}, True: {False: True, True: False}}
In which line this code raises an exception, and which is the exception (e.g. ValueError, TypeError...)?
In[6]: foo = {(a, b): foo for a in foo for b in foo}
In[7]: bar = foo[0, 0][0][0]
In[8]: foo = {(a, b): foo for a in foo.keys() for b in foo.keys()}
In[9]: bar = foo[(0, 0), (0, 0)][0, 0][0][0]
In[10]: foo = {(a, b): foo for a in foo.values() for b in foo.values()
TypeError Traceback (most recent call last)
<ipython-input-49-56010e2be892> in <dictcomp>(.0)
9 bar = foo[(0, 0), (0, 0)][0, 0][0][0]
---> 10 foo = {(a, b): foo for a in foo.values() for b in foo.values()}
11 bar = foo[[0, 0], [0, 0]][0, 0][0][0]
TypeError: unhashable type: 'dict'
>>> import itertools
>>> import random
>>> import bisect
>>>
>>> candidates = [0, 99, 666, 22]
>>> weights = [.33, .33, 99., .34]
>>> cum_weights = itertools.accumulate(weights)
>>> candidates[bisect.bisect(cum_weights, random.random() * cum_weights[-1])]
Which of these projects is not a NumFOCUS fiscally sponsored project?
>>> import who_am_i as wai
>>> import numpy as np
>>> from sklearn.pipeline import make_pipeline
>>> from sklearn.dummy import DummyClassifier
>>>
>>> X = np.array([[ 1., -1., 2.],
... [ 2., np.nan, 0.],
... [ 0., 1., -1.]])
>>> y = np.array([0., 1., 0.])
>>>
>>> clf = make_pipeline(wai.Imputer(),
... wai.StandardScaler(),
... DummyClassifier())
>>>
>>> clf.fit(X, y)
>>> clf.predict(np.array([[2., 0., -1.]]))
Which is the biggest enemy of the People's Front of Judea?
Which is the latest released version of Pandas?
Who was the founder of the Barcelona Python Meetup?
Given a dataset where the number of samples is much larger than the number of features, and these are continuous, which of the next models should require less parameters:
Sort them from faster to slower:
>>> import random
>>> import numpy as np
>>>
>>> rand_list = [random.randint(0, 2 ** 32) for i in range(1_000_000)]
>>>
>>> %timeit list(map(lambda x: x ** 2, rand_list))
>>> %timeit [x ** 2 for x in rand_list]
>>> %timeit np.array(rand_list) ** 2
In which line this code raises an exception, and which is the exception (e.g. ValueError, TypeError...)?
In[1]: import pandas as pd
In[2]: df = pd.DataFrame({'value': [1, 2, 3]},
...: index=[10, 20, 30])
In[3]: df.loc[[10, 20, 30]] + df.iloc[[0, 1, 2]] + df.ix[[0, 1, 2]]
>>> import itertools
>>> import random
>>> import bisect
>>>
>>> candidates = [0, 99, 666, 22]
>>> weights = [.33, .33, 99., .34]
>>> cum_weights = list(itertools.accumulate(weights))
>>> cum_weights
[0.33, 0.66, 99.66, 100.0]
>>> random_number = random.random() * cum_weights[-1]
>>> # uniformly distributed between 0 and 100
>>> # 99% probability of being between 0.66 and 99.66
>>> random_number
58.95397201789591
>>> index = bisect.bisect(cum_weights, random_number)
>>> index
2
>>> candidates[index]
666
>>> import itertools
>>> import random
>>> import bisect
>>>
>>> candidates = [0, 99, 666, 22]
>>> weights = [.33, .33, 99., .34]
>>> cum_weights = itertools.accumulate(weights)
>>> candidates[bisect.bisect(cum_weights, random.random() * cum_weights[-1])]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-7-76cc035203d4> in <module>()
6 weights = [.33, .33, 99., .34]
7 cum_weights = itertools.accumulate(weights)
----> 8 candidates[bisect.bisect(cum_weights, random.random() * cum_weights[-1])]
TypeError: 'itertools.accumulate' object is not subscriptable
Which of these projects is not a NumFOCUS fiscally sponsored project?
Which of these projects is not a NumFOCUS fiscally sponsored project?
>>> import who_am_i as wai
>>> import numpy as np
>>> from sklearn.pipeline import make_pipeline
>>> from sklearn.dummy import DummyClassifier
>>>
>>> X = np.array([[ 1., -1., 2.],
... [ 2., np.nan, 0.],
... [ 0., 1., -1.]])
>>> y = np.array([0., 1., 0.])
>>>
>>> clf = make_pipeline(wai.Imputer(),
... wai.StandardScaler(),
... DummyClassifier())
>>>
>>> clf.fit(X, y)
>>> clf.predict(np.array([[2., 0., -1.]]))
>>> import sklearn.preprocessing
>>> import numpy as np
>>> from sklearn.pipeline import make_pipeline
>>> from sklearn.dummy import DummyClassifier
>>>
>>> X = np.array([[ 1., -1., 2.],
... [ 2., np.nan, 0.],
... [ 0., 1., -1.]])
>>> y = np.array([0., 1., 0.])
>>>
>>> clf = make_pipeline(sklearn.preprocessing.Imputer(),
... sklearn.preprocessing.StandardScaler(),
... DummyClassifier())
>>>
>>> clf.fit(X, y)
>>> clf.predict(np.array([[2., 0., -1.]]))
array([ 1.])
Which is the biggest enemy of the People's Front of Judea?
Which is the latest released version of Pandas?
Who was the founder of the Barcelona Python Meetup?
Given a dataset where the number of samples is much larger than the number of features, which of the next models should require less parameters. The features are continuos, and there is no pattern in the features to discriminate the response variable.
Sort them from faster to slower:
>>> import random
>>> import numpy as np
>>>
>>> rand_list = [random.randint(0, 2 ** 32) for i in range(1_000_000)]
>>>
>>> %timeit list(map(lambda x: x ** 2, rand_list)) # 589 ms ± 6.77 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
>>> %timeit [x ** 2 for x in rand_list] # 478 ms ± 1.32 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
>>> %timeit np.array(rand_list) ** 2 # 117 ms ± 21.3 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
In which line this code raises an exception, and which is the exception (e.g. ValueError, TypeError...)?
In[1]: import pandas as pd
In[2]: df = pd.DataFrame({'value': [1, 2, 3]},
...: index=[10, 20, 30])
In[3]: df.loc[[10, 20, 30]] + df.iloc[[0, 1, 2]] + df.ix[[0, 1, 2]]
In which line this code raises an exception, and which is the exception (e.g. ValueError, TypeError...)?
In[1]: import pandas as pd
In[2]: df = pd.DataFrame({'value': [1, 2, 3]},
...: index=[10, 20, 30])
In[3]: df.loc[[10, 20, 30]] + df.iloc[[0, 1, 2]] + df.ix[[0, 1, 2]]
DeprecationWarning:
.ix is deprecated. Please use
.loc for label based indexing or
.iloc for positional indexing
See the documentation here:
http://pandas.pydata.org/pandas-docs/stable/indexing.html#deprecate_ix
#!~/.anaconda3/bin/python
Out[3]:
value
0 NaN
1 NaN
2 NaN
10 NaN
20 NaN
30 NaN
In [ ]: